angular.module('allorders', [])
    .controller('allordersCtrl', ['$scope', 'httpService', 'alertmsg', function($scope, httpService, alertmsg) {

        var pagenum = 1;
        $scope.getOrders = function(page) {
            if (page) {
                pagenum = page;
            }
            httpService.query("web/orders", { type: 'service', page: pagenum, limit: limit }).then(function(res) {
                if (res.code == 200) {
                    $scope.orders = res.orders;
                    $scope.page = res.page;
                }
            })
        };
        $scope.getOrders(1);

        // 抢订单
        $scope.competeOrder = function(id, index) {
            httpService.query('web/orders/' + id + '/compete_order', undefined, 'post').then(function(res) {
                if (res.code == 200) {
                    $scope.orders.splice(index, 1);
                    alertmsg('抢单成功!你可以在<a style="color:#58c676!important;" href="/mine/list/angular-flatpickr,orders">我的订单</a>中查看');
                } else {
                    alertmsg(res.msg);
                }
            })
        };

        var head = document.getElementsByTagName('head')[0];
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = 'https://webapi.amap.com/maps?v=1.3&key=b1a49ba5623930057d0c66c629c98af9';
        head.appendChild(script);
        script.onload = function() {}

    }]);
